package com.yanqu.road.server.cmd.union;

import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.UnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.utils.string.StringUtils;

//@Cmd(code = Protocol.S_UNION_DELETE, desc = "解散联盟")
public class DeleteUnionCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		// 判断权限 族长
		String unionUid = player.getUserInfo().getUnionUid();
		if(StringUtils.isNullOrEmpty(unionUid)){
			ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
			return;
		}
		UnionInfo unionInfo = UnionMgr.getUnionInfo(unionUid);
		if(null == unionInfo){
			ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
			return;
		}
		if (unionInfo.getMasterUserId() == player.getUserId()) {
			ret = UnionMgr.deleteUnion(player);
		} else {
			ret = GameErrorCode.E_UNION_POSITION_NO_ENOUGH;
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		UnionProto.UnionDeleteRespMsg.Builder respMsg = UnionProto.UnionDeleteRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_UNION_DELETE, respMsg);
	}

}
